import React from 'react';
import { connect } from 'react-redux';
import { setTitle } from '../../actions/topAction';
import MenuItem from 'material-ui/lib/menus/menu-item';
import Divider from 'material-ui/lib/divider';
import ArrowDropRight from 'material-ui/lib/svg-icons/navigation-arrow-drop-right';
import MenuIcon from 'material-ui/lib/svg-icons/navigation/menu';

import { Link } from 'react-router';

import * as MenuStyle from './Menu.less';
import cx from 'classnames';

import createHistory from '../../../routes/history';

const LinkStyle = cx(MenuStyle.color_black, MenuStyle.full);

class Menu extends React.Component {
	constructor(props) {
		super(props);

		this.handlePushLocation = this.handlePushLocation.bind(this);
	}

	handlePushLocation(url) {
		let history = createHistory();
		let location = history.createLocation(url, null);
		history.push(location);

		if (location.hash) {
			let { dispatch } = this.props;
			dispatch(setTitle(decodeURI(location.hash.replace('#', ''))));
		}
	}

	componentDidMount() {
		let { location, dispatch } = this.props;
		if (location.hash) {
			dispatch(setTitle(decodeURI(location.hash.replace('#', ''))));
		}
	}

	render() {
		return (
			<div className={MenuStyle.menu}>
				<MenuItem primaryText='导航' disabled={true} rightIcon={<MenuIcon />} />
				<Divider />
				<MenuItem primaryText='新增用户数据' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='教师新增数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='新增教师趋势图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('新增教师趋势图')}`)} } />,
						<MenuItem primaryText='教师-班级-学校分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('教师-班级-学校分布图')}`)} } />,
						<MenuItem primaryText='教师区域分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/teacher.html#${encodeURI('教师区域分布图')}`)} } />,
						<MenuItem primaryText='教师区域新增走势图' disabled={true} secondaryText='building...' />,
						<MenuItem primaryText='教师身份认证分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('教师身份认证分布图')}`)} } />,
						<MenuItem primaryText='教师性别分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/teacher.html#${encodeURI('教师性别分布图')}`)} } />,
					]}/>,
					<MenuItem primaryText='学生新增数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='新增学生趋势图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('新增学生趋势图')}`)} } />,
						<MenuItem primaryText='学生-加班分布图' disabled={true} secondaryText='building...' />,
						<MenuItem primaryText='学生区域分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生区域分布图')}`)}} />,
						<MenuItem primaryText='学生区域新增走势图' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='学生年级分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生年级分布图')}`)}} />,
						<MenuItem primaryText='学生性别分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生性别分布图')}`)}} />,
					]}/>
				]}  />
				<MenuItem primaryText='累计用户数据' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='教师累计数据' rightIcon={<ArrowDropRight/>} menuItems={[
						<MenuItem primaryText='累计教师趋势图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('累计教师趋势图')}`)}} />,
						<MenuItem primaryText='教师-班级-学校分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('教师-班级-学校分布图')}`)}} />,
						<MenuItem primaryText='教师区域分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/teacher.html#${encodeURI('教师区域分布图')}`)}} />,
						<MenuItem primaryText='教师区域累计走势图' secondaryText='building...' disabled={true}/>,
						<MenuItem primaryText='教师性别分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/teacher.html#${encodeURI('教师性别分布图')}`)}} />,
						<MenuItem primaryText='教师身份认证分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('教师身份认证分布图')}`)}} />,
					]} />,
					<MenuItem primaryText='学生累计数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='累计学生趋势图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/user.html#${encodeURI('累计学生趋势图')}`)}} />,
						<MenuItem primaryText='学生-加班分布图' secondaryText='building...' disabled={true}/>,
						<MenuItem primaryText='学生区域分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生区域分布图')}`)}} />,
						<MenuItem primaryText='学生区域累计走势图' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='学生年级分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生年级分布图')}`)}} />,
						<MenuItem primaryText='学生性别分布图'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/userAnalysis/student.html#${encodeURI('学生性别分布图')}`)}} />,
					]}/>
				]} />
				<MenuItem primaryText='留存数据' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='教师留存数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='教师启动留存数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/retention.html#${encodeURI('教师启动留存数据')}`)}} />,
						<MenuItem primaryText='教师布置作业留存数'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/retention.html#${encodeURI('教师布置作业留存数据')}`)}} />,

					]}/>,
					<MenuItem primaryText='学生留存数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='学生启动留存数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/retention.html#${encodeURI('学生启动留存数据')}`)}} />,
						<MenuItem primaryText='学生提交作业留存数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/datasummary/retention.html#${encodeURI('学生提交作业留存数据')}`)}} />,
						<MenuItem primaryText='学生闯关留存数据'
							onTouchTap={() => { this.handlePushLocation(`/app/StudentMissionRetained#${encodeURI('学生闯关留存数据')}`)}} />,
					]} />
				]} />
				<MenuItem primaryText='活跃数据' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='教师活跃数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='教师启动活跃数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/userStructure.html#${encodeURI('教师启动活跃数据')}`)}} />,
						<MenuItem primaryText='教师新鲜度分析'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/teacher.html#${encodeURI('教师新鲜度分析')}`)}} />,
						<MenuItem primaryText='教师布置作业活跃数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/userStructure.html#${encodeURI('教师布置作业活跃数据')}`)}} />,
						<MenuItem primaryText='教师启动活跃-区域分布' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='教师布置作业活跃-区域分布' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='教师启动活跃数据' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='教师布置作业活跃数据' secondaryText='building...' disabled={true} />,
					]} />,
					<MenuItem primaryText='学生活跃数据' rightIcon={<ArrowDropRight />} menuItems={[
						<MenuItem primaryText='学生启动活跃数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/userStructure.html#${encodeURI('学生启动活跃数据')}`)}} />,
						<MenuItem primaryText='学生新鲜度分析'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/student.html#${encodeURI('学生新鲜度分析')}`)}} />,
						<MenuItem primaryText='学生提交活跃数据'
							onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/userStructure.html#${encodeURI('学生提交活跃数据')}`)}} />,
						<MenuItem primaryText='学生启动活跃-区域分布' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='学生提交活跃-区域分布' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='学生启动活跃数据' secondaryText='building...' disabled={true} />,
						<MenuItem primaryText='学生提交活跃数据' secondaryText='building...' disabled={true} />,
					]} />
				]} />
				<MenuItem primaryText='布置作业-老师-题目' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='新增趋势'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkNewTrend#${encodeURI('新增趋势')}`)}} />,
					<MenuItem primaryText='累积趋势'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkCumulativeTrend#${encodeURI('累积趋势')}`)}} />,
					<MenuItem primaryText='科目分布'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkSubjectDistribution#${encodeURI('科目分布')}`)}} />,
					<MenuItem primaryText='地域分布'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkAreaDistribution#${encodeURI('地域分布')}`)}} />,
					<MenuItem primaryText='布置作业提交率(按截止日期)'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkSubmissionRate#${encodeURI('布置作业提交率(按截止日期)')}`)}} />,
					<MenuItem primaryText='布置作业题目题型分布'
						onTouchTap={() => { this.handlePushLocation(`/app/FixupWorkQuestionsDistribution#${encodeURI('布置作业题目题型分布')}`)}} />,
					<MenuItem primaryText='布置作业老师新鲜度分析'
						onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/assignhomework.html#${encodeURI('布置作业老师新鲜度分析')}`)}} />,
					]} />
				<MenuItem primaryText='提交作业-学生-题目' rightIcon={<ArrowDropRight />} menuItems={[
					<MenuItem primaryText='新增趋势'
						onTouchTap={() => { this.handlePushLocation(`/app/SubmitWorkNewTrend#${encodeURI('新增趋势')}`)}} />,
					<MenuItem primaryText='累积趋势'
						onTouchTap={() => { this.handlePushLocation(`/app/SubmitWorkCumulativeTrend#${encodeURI('累积趋势')}`)}} />,
					<MenuItem primaryText='科目分布'
						onTouchTap={() => { this.handlePushLocation(`/app/SubmitWorkSubjectDistribution#${encodeURI('科目分布')}`)}} />,
					<MenuItem primaryText='地域分布'
						onTouchTap={() => { this.handlePushLocation(`/app/SubmitWorkAreaDistribution#${encodeURI('地域分布')}`)}} />,
					<MenuItem disabled={true} primaryText='提交作业题目题型分布' secondaryText='building...' />,
                    <MenuItem primaryText='提交作业学生新鲜度分析'
                        onTouchTap={() => { this.handlePushLocation(`/app/html/knowbox/activeness/commithomework.html#${encodeURI('提交作业学生新鲜度分析')}`)}} />,
                ]} />
                <MenuItem primaryText='用题分析' rightIcon={<ArrowDropRight />} menuItems={[
                    <MenuItem primaryText='分类用题分析'
                    	onTouchTap={() => { this.handlePushLocation(`/app/ExaminationAnalysisExamFlow#${encodeURI('分类用题分析')}`)}} />,
                    <MenuItem primaryText='推荐作业'
                    	onTouchTap={() => { this.handlePushLocation(`/app/ExaminationAnalysisRecommendation#${encodeURI('推荐作业')}`)}} />,
                    <MenuItem primaryText='题库用题来源分布'
                    	onTouchTap={() => { this.handlePushLocation(`/app/ExaminationAnalysisSourceDistribution#${encodeURI('题库用题来源分布')}`)}} />
                ]} />
                <MenuItem primaryText='活动分析' onTouchTap={() => { this.handlePushLocation(`/app/ActivityAnalysisInvite#${encodeURI('邀请数据分析')}`)}} />
                <MenuItem primaryText='自主练习' rightIcon={<ArrowDropRight />} menuItems={[
                	<MenuItem primaryText='练习数据分析'
                		onTouchTap={() => { this.handlePushLocation(`/app/IndependentPractice#${encodeURI('练习数据')}`)}} />,
                	<MenuItem primaryText='闯关深度分析'
                		onTouchTap={() => { this.handlePushLocation(`/app/DepthMission#${encodeURI('闯关深度分析')}`)}} />
                ]} />
            </div>
        );
	}
}

export default connect((state)=>({location: state.router.location}))(Menu);

